import 'package:flutter/material.dart';
import '../../../../../lib_basemodel/chat_room/chat/hb_rtm_message_type.dart';
import '../../../msg/room_msg.dart';
import 'room_msg_item_builder.dart';
import 'widget/show_items_widget.dart';

/// 公屏消息builder，富文本消息
class RoomTextMsgItemBuilder with RoomMsgItemBuilder {
  @override
  bool support(RoomMsg msg) => true;

  @override
  Widget buildContent(BuildContext context, RoomMsg msg) {
    return _generateContentContainer(
      context,
      msg,
      ShowItemsWidget(
        chatContent: msg.chatContent,
        rtmMsg: msg.rtmMsg,
      ),
    );
  }

  Widget _generateContentContainer(
    BuildContext context,
    RoomMsg msg,
    Widget? body,
  ) {
    final hasBg =
        (msg.rtmMsg?.rtmType != HBRtmMessageType.rtmSmallMessageTypeUserJoin);

    /// 带圆角背景
    Widget bgWidget = Container(
        decoration: BoxDecoration(
            borderRadius: const BorderRadiusDirectional.only(
              topStart: Radius.circular(8),
              topEnd: Radius.circular(8),
              bottomStart: Radius.circular(8),
              bottomEnd: Radius.circular(8),
            ),
            gradient: LinearGradient(
                colors: [
                  const Color(0xFFFFFFFF).withValues(alpha: 0.05),
                  const Color(0xFFFFFFFF).withValues(alpha: 0.05)
                ],
                begin: AlignmentDirectional.bottomStart,
                end: AlignmentDirectional.topEnd)),
        padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
        child: body);

    /// 不带圆角背景
    Widget noBgWidget = Container(
        decoration: const BoxDecoration(
          borderRadius: BorderRadiusDirectional.only(
            topStart: Radius.circular(8),
            topEnd: Radius.circular(8),
          ),
        ),
        child: body);

    return Stack(
      clipBehavior: Clip.none,
      children: [
        hasBg ? bgWidget : noBgWidget,
      ],
    );
  }
}
